package com.cs.pk.form;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbenchWindow;

public class CodeReviewForm_website{
	
	private IWorkbenchWindow parent = null;
	private Text titleText,descriptionText,fileText,bugId,yourEmail,reviewers,cc= null;
	private Combo repository,project = null;
	
	public CodeReviewForm_website(IWorkbenchWindow parent) {
		this.parent = parent;
	}
	
	public void createForm(ImageDescriptor iDescriptor) {
		Shell shell = new Shell(parent.getShell(), SWT.DIALOG_TRIM | SWT.PRIMARY_MODAL |SWT.RESIZE);
		shell.setLayout(new GridLayout(1, false));
		shell.setImage(iDescriptor.createImage());
		Rectangle bounds = parent.getShell().getMonitor().getBounds();

		shell.setBounds(bounds.width/8,bounds.height/14,bounds.width*3/4,bounds.height*8/9);
		prepareForm(shell);
		shell.open();

	}
	
	private void prepareForm(Composite parent) {
		
		Group codeReview = new Group(parent,SWT.NONE);
		codeReview.setText("Create new topic");
		GridLayout gl = new GridLayout();
		gl.numColumns = 3;
		codeReview.setLayout(gl);
		setSpan(codeReview, 1,1, GridData.FILL_HORIZONTAL);
		
		setSpan(createLabel(codeReview, "Topic title:"),3,1,GridData.BEGINNING|GridData.FILL_HORIZONTAL);
		titleText = new Text(codeReview,SWT.SINGLE|SWT.BORDER);
		setSpan(titleText, 3, 1, GridData.FILL_HORIZONTAL);
		
		setSpan(createLabel(codeReview, "Topic description:"), 3, 1, GridData.BEGINNING|GridData.FILL_HORIZONTAL);
		descriptionText = new Text(codeReview,SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
		setSpan(descriptionText, 3, 20, GridData.FILL_BOTH);
	
		createLabel(codeReview, "Topic text upload:");
		fileText = new Text(codeReview,SWT.SINGLE|SWT.BORDER|SWT.READ_ONLY);
		setSpan(fileText, 1, 1, GridData.BEGINNING|GridData.FILL_HORIZONTAL);
		
		Button chooseFile = new Button(codeReview,SWT.PUSH);			
		chooseFile.setText("Choose file"); 
		
		createLabel(codeReview, "Repository:");
		repository = new Combo(codeReview,SWT.DROP_DOWN|SWT.READ_ONLY);
		setSpan(repository, 2,1, GridData.FILL);
		
		createLabel(codeReview, "Project:");
		project = new Combo(codeReview,SWT.DROP_DOWN|SWT.READ_ONLY);
		setSpan(project, 2, 1, GridData.FILL);
		
		createLabel(codeReview, "Bug IDs:");
		bugId = new Text(codeReview,SWT.SINGLE|SWT.BORDER);
		setSpan(bugId, 2, 1, GridData.FILL_HORIZONTAL);
		
		createLabel(codeReview, "Your email address: ");
		yourEmail = new Text(codeReview,SWT.SINGLE|SWT.BORDER);
		setSpan(yourEmail, 2, 1, GridData.FILL_HORIZONTAL);
		
		createLabel(codeReview, "Reviewers:");
		reviewers = new Text(codeReview,SWT.SINGLE|SWT.BORDER);
		setSpan(reviewers, 2, 1, GridData.FILL_HORIZONTAL);
		
		createLabel(codeReview, "Cc: ");
		cc = new Text(codeReview,SWT.SINGLE|SWT.BORDER);
		setSpan(cc, 2, 1, GridData.FILL_HORIZONTAL);
		
		Button createTopic = new Button(codeReview,SWT.PUSH);			
		createTopic.setText("Create Topic");		
	}
	
	private void populateCombo(Combo c) {
		
	}
	
//	private void createCRView(Composite parent) {
//		
//		Group view = new Group(parent,SWT.NONE);
//		view.setText("ClearCase");
//		GridLayout gl = new GridLayout();
//		gl.numColumns = 3;
//		view.setLayout(gl);		
//		setSpan(view, 1,1, GridData.FILL_HORIZONTAL);
//		
//		createLabel(view, "View : ");
//		
//		Combo viewCombo = new Combo(view,SWT.DROP_DOWN|SWT.READ_ONLY);		
//		setSpan(viewCombo, 2, 1,GridData.FILL_HORIZONTAL);
//		
//		createLabel(view, "Activity : ");
//		
//		Combo activityCombo = new Combo(view,SWT.DROP_DOWN|SWT.READ_ONLY);		
//		setSpan(activityCombo, 1, 1, GridData.FILL_HORIZONTAL);
//		
//		Button refresh = new Button(view,SWT.PUSH);			
//		refresh.setImage(Activator.getImageDescriptor("icons/refresh.gif").createImage());
//		
//	}
	
//	private void createCRReview(Composite parent) {
//		Group review = new Group(parent,SWT.NONE);
//		review.setText("Review");
//		
//		GridLayout glr = new GridLayout();
//		glr.numColumns = 3;
//		review.setLayout(glr);
//		setSpan(review, 1, 1,GridData.FILL_HORIZONTAL);
//		
//		createLabel(review, "Title : ");
//		
//		Text titleBox = new Text(review,SWT.SINGLE|SWT.BORDER);
//		setSpan(titleBox, 2,1, GridData.FILL_HORIZONTAL);
//		
//		createLabel(review, "Obsoletes : ");
//		
//		Combo obsCombo = new Combo(review,SWT.DROP_DOWN|SWT.READ_ONLY);
//		setSpan(obsCombo, 1,1, GridData.FILL_HORIZONTAL);
//		
//		Button refresh = new Button(review,SWT.PUSH);
//		refresh.setImage(Activator.getImageDescriptor("icons/refresh.gif").createImage());
//		
//		createLabel(review, "Target Stream : ");
//		
//		Combo stream = new Combo(review,SWT.DROP_DOWN|SWT.READ_ONLY);
//		setSpan(stream, 2,1, GridData.FILL_HORIZONTAL);
//		
//		createLabel(review, "Project : ");
//		
//		Combo project = new Combo(review,SWT.DROP_DOWN|SWT.READ_ONLY);
//		setSpan(project, 2, 1,GridData.FILL_HORIZONTAL);
//		
//		createLabel(review, "EmailAddress");
//		
//		Text email = new Text(review,SWT.SINGLE|SWT.BORDER);
//		setSpan(email, 2, 1,GridData.FILL_HORIZONTAL);
//		
//		Button reviewer = new Button(review,SWT.PUSH);
//		reviewer.setText("Reviewers..");
//		
//		Text rEmail = new Text(review,SWT.SINGLE|SWT.BORDER);
//		setSpan(rEmail, 2,1, GridData.FILL_HORIZONTAL);
//		
//		Button ccs = new Button(review,SWT.PUSH);
//		ccs.setText("CC..");
//		
//		Text ccMail = new Text(review,SWT.SINGLE|SWT.BORDER);
//		setSpan(ccMail, 2, 1,GridData.FILL_HORIZONTAL);
//		
//		
//		Button checkBox = new Button(review,SWT.CHECK);
//		checkBox.setText("Copy ClearQuest");
//		
//		setSpan(createLabel(review, "Description :- "), 3,1, GridData.FILL_HORIZONTAL);
//		Text descText = new Text(review,SWT.MULTI | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
//		setSpan(descText, 3, 20, GridData.FILL_BOTH);
//		
//	}
//	
//	private void createCRFiles(Composite parent) {
//		Group files = new Group(parent,SWT.NONE);
//		files.setText("Files");
//		GridLayout gl = new GridLayout();
//		gl.numColumns = 1;
//		files.setLayout(gl);
//		setSpan(files, 1, 1, GridData.FILL_HORIZONTAL);
//		
//		Button refreshFileList = new Button(files,SWT.PUSH);
//		refreshFileList.setImage(Activator.getImageDescriptor("icons/refresh.gif").createImage());
//		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
//		gd.horizontalSpan=3;
//		gd.horizontalAlignment = SWT.END;
//		refreshFileList.setLayoutData(gd);
//		
//		Table fileList = new Table(files,SWT.MULTI | SWT.BORDER | SWT.H_SCROLL
//		        | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.HIDE_SELECTION) ;
//		fileList.setLinesVisible(true);
//		fileList.setHeaderVisible(true);
//		setSpan(fileList, 1, 20, GridData.FILL_BOTH);
//		int width = parent.getClientArea().width;
//		for(int i=0;i<tableHeaders().length;i++) {
//			TableColumn column = new TableColumn(fileList,SWT.LEFT);
//			column.setText(tableHeaders()[i]);
//			if(i==(tableHeaders().length-1)) {
//				column.setWidth(width>0?width:70);
//			}else {
//			   column.setWidth(70);
//			   width = width-70;			   
//			}
//		}
//		fileList.pack();
//	}
//	
//	private void statusPanel(Composite parent) {
//		
//		Label label = new Label(parent,SWT.NONE|SWT.BOLD);
//		label.setText("Done..");
//		
//		GridData gd = new GridData(GridData.FILL_HORIZONTAL);
//		gd.horizontalAlignment = GridData.END;
//		Button submit = new Button(parent,SWT.PUSH);
//		submit.setText("Submit Review");	
//		submit.setLayoutData(gd);
//		
//	}
//	
//	private String[] tableHeaders() {
//		return new String[]{"Include?","File","Version"};
//	}
//	
//	
	private Label createLabel(Group g,String text) {
		Label l = new Label(g,SWT.NONE);
		l.setText(text);
		return l;
	}
	
	
	private GridData setSpan(Control widget,int horizontalSpan,int verticalSpan,int style) {
		GridData gd = new GridData(style);
		gd.horizontalSpan = horizontalSpan;
		gd.verticalSpan = verticalSpan;
		widget.setLayoutData(gd);
		return gd;
	}
	
}
